package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArHomeShop;
import net.sk.china.city.service.IArHomeShopService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 店铺管理Controller
 * 
 * @author gxf
 * @date 2024-05-08
 */
@Api(tags = "店铺管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/yigoHome/shop")
public class ArHomeShopController extends BaseController
{
    @Autowired
    private IArHomeShopService arHomeShopService;

    /**
     * 查询店铺管理列表
     */
    @ApiOperation("店铺列表")
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArHomeShop arHomeShop)
    {
        startPage();
        List<ArHomeShop> list = arHomeShopService.selectArHomeShopList(arHomeShop);
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArHomeShop arHomeShop)
    {
        List<ArHomeShop> list = arHomeShopService.selectArHomeShopList(arHomeShop);
//        ExcelUtil<ArHomeShop> util = new ExcelUtil<ArHomeShop>(ArHomeShop.class);
//        util.exportExcel(response, list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @ApiOperation("店铺详情")
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arHomeShopService.selectArHomeShopById(id));
    }

    /**
     * 新增店铺管理
     */
    @ApiOperation("新增店铺")
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArHomeShop arHomeShop)
    {
        return toAjax(arHomeShopService.insertArHomeShop(arHomeShop));
    }

    /**
     * 修改店铺管理
     */
    @ApiOperation("修改店铺")
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArHomeShop arHomeShop)
    {
        return toAjax(arHomeShopService.updateArHomeShop(arHomeShop));
    }

    /**
     * 删除店铺管理
     */
    @ApiOperation("删除店铺")
    @PreAuthorize("hasAnyAuthority('yigoHome:shop:remove')")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long[] id)
    {
        return toAjax(arHomeShopService.deleteArHomeShopByIds(id));
    }


    @ApiOperation("获取所有店铺")
    @GetMapping("/getShops")
    public AjaxResult getShops()
    {
        return success(arHomeShopService.getShops());
    }
}
